package com.example.shiyan2;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class ThreeActivity extends AppCompatActivity {
    private ImageView[] imageViews;
    private int currentIndex = 0;
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            showNextImage();
            handler.postDelayed(this, 3000); // 每3秒切换一次
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_three);

        Button back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

//        FrameLayout frameLayout = findViewById(R.id.frameLayout);
        imageViews = new ImageView[]{
                findViewById(R.id.imageView1),
                findViewById(R.id.imageView2),
                findViewById(R.id.imageView3),
                findViewById(R.id.imageView4),
                findViewById(R.id.imageView5)
        };

        // 显示第一个图片
        imageViews[currentIndex].setVisibility(ImageView.VISIBLE);

        // 启动定时器
        handler.postDelayed(runnable, 3000);
    }







    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacks(runnable);
    }

    private void showNextImage() {
        imageViews[currentIndex].setVisibility(ImageView.GONE);
        currentIndex = (currentIndex + 1) % imageViews.length;
        imageViews[currentIndex].setVisibility(ImageView.VISIBLE);
    }


    }
